<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
 session_start();

 include("../main/function.php");
 include("../main/ShowPage.class.php");
 include("../main/islogin.php");
 $db=new Db();
  //当$action 为 add 时 新增教师信息
 //当$action 为 edit 时 修改教师信息

$action=$_GET["action"];

 if($action=='edit')
 {
	$teacher_add_msg=$_POST['teacher_add_msg']; //标记
		$id=$_POST['id']; //id
		$name=$_POST['name']; //姓名 
		$sex=$_POST['sex']; //性别
		$birth=$_POST['birth']; //出生日期
		$idcard=$_POST['idcard']; //身份证
		$oldphoto=$_POST['oldphoto']; //照片
		$partisan=$_POST['partisan']; //政治面貌 
		$area=$_POST['area']; //所在院系
		$family=$_POST['family']; //民族
		//$company=$_POST['company']; //所在单位 
		//$zhuanye=$_POST['zhuanye']; //所学专业 
		$phone=$_POST['phone']; //手机 
		$tel=$_POST['tel']; //固话 
		$email=$_POST['email']; //电子邮箱 
		$education=$_POST['education']; //学历 
		$degree=$_POST['degree']; //学位 
		$graduation_time=$_POST['graduation_time']; //毕业时间 
		$graduation_school=$_POST['graduation_school']; //毕业院校 
		$work_time=$_POST['work_time']; //参加工作时间 
		$post=$_POST['post']; //职务 
		$title=$_POST['title']; //职称 
		$title_time=$_POST['title_time']; //职称 评定时间
		//$office=$_POST['office']; //现聘请职称
		//$current=$_POST['current']; //现任职 
		//$teached=$_POST['teached']; //教学经历 
		$train=$_POST['train']; //培训经历 
		$award=$_POST['award']; //获奖情况 
		
		//////////////////
		/*$teach_language=$_POST['teach_language']; //授课语言
		$language_level=$_POST['language_level']; //外语水平
		$teach_course=$_POST['teach_course']; //讲授课程
		$research_direction=$_POST['research_direction']; //研究方向
		$main_achievements=$_POST['main_achievements']; //主要成果*/
		////////////////// 
		
		$user=$_SESSION['user']; //添加用户 
		$time=date('y-m-d H:i:s',time());//$_POST['name']; //添加时间 
		$mem=$_POST['mem']; //备注
		
		
		//新增图片信息		//处理上传图片
		$picName1="";
		$uploadmsg=0;
		if (is_uploaded_file($_FILES['photo']['tmp_name'])) 
		{
		 	//exit($_FILES['pic']['tmp_name']);
			$upfile=$_FILES["photo"];
			$pname=substr($upfile["name"],-4,4);
			$type=$upfile["type"];
			$tmp_name=$upfile["tmp_name"];
			$size=$upfile["size"];
			$error=$upfile["error"];
			switch ($type) 
			{
				case 'image/pjpeg':
					$alow="OK";
					break;
				case 'image/jpeg':
					$alow="OK";
					break;
				case 'image/gif':
					$alow="OK";
					break;
				case 'image/x-png':
					$alow="OK";
					break;
				case 'image/bmp':
					$alow="OK";
					break;
			}
			if ($alow&&$error==0)
			 {
				$radom=rand(1,100000);
				$picName1='photo'.$radom.$pname;
				move_uploaded_file($tmp_name,'../images/photo/'.$picName1);
				$uploadmsg=1;
			}
			if($picName1=='')
			{
				echo "<script>alert('图片太大或者格式不正确，请重新上传。');history.back();</script>";
				exit();
			}
		}
		if($uploadmsg)
		{
			$oldphoto=$picName1;
		}
	 $sql="update teacher set 
							`name`='$name' ,
							`sex`='$sex' ,
							`birth`='$birth' ,
							`idcard`='$idcard' ,
							`photo`='$oldphoto' ,
							`partisan`='$partisan' ,
							`area`='$area' ,
							`family`='$family' ,
							`phone`='$phone' ,
							`tel`='$tel' ,
							`email`='$email' ,
							`education`='$education' ,
							`degree`='$degree' ,
							`graduation_time`='$graduation_time' ,
							`graduation_school`='$graduation_school' ,
							`work_time`='$work_time' ,
							`post`='$post' ,
							`title`='$title' ,
							`title_time`='$title_time' ,
							`train`='$train' ,
							`award`='$award' ,
							`teach_course`='$teach_course' ,
							`research_direction`='$research_direction' ,
							`main_achievements`='$main_achievements' ,
							`user`='$user' ,
							`time`='$time' ,
							`mem`='$mem'  where id=$id";
		$teacher=$db->query($sql);
		if($teacher>=1)
		{
			 if('1'==$teacher_add_msg)
			 {
			 	echo "<script>alert('更新信息成功');history.back();</script>";
			 }
			 echo "<script>alert('修改成功');history.go(-1);</script>";
		}
		else
		{
			 echo "<script>alert('修改失败');history.back();</script>";
		}
}
else  if($action=='add')
{
			$id=$_POST['id']; //id
			$name=$_POST['name']; //姓名 
			$sex=$_POST['sex']; //性别
			$birth=$_POST['birth']; //出生日期
			$idcard=$_POST['idcard']; //身份证
			$partisan=$_POST['partisan']; //政治面貌 
			$area=$_POST['area']; //地区 
			$family=$_POST['family']; //名族
			$company=$_POST['company']; //所在单位 
			$phone=$_POST['phone']; //手机 
			$tel=$_POST['tel']; //固话 
			$email=$_POST['email']; //电子邮箱 
			$education=$_POST['education']; //学历 
			$degree=$_POST['degree']; //学位 
			$graduation_time=$_POST['graduation_time']; //毕业时间 
			$graduation_school=$_POST['graduation_school']; //毕业院校 
			$work_time=$_POST['work_time']; //参加工作时间 
			$post=$_POST['post']; //职务 
			$title=$_POST['title']; //职称 
			$title_time=$_POST['title_time']; //职称 评定时间
			$office=$_POST['office']; //现聘职称 
			$train=$_POST['train']; //培训经历 
			$current=$_POST['current']; //现任职 
			$teached=$_POST['teached']; //教学经历 
			$award=$_POST['award']; //获奖情况 
			$user=$_SESSION['user']; //添加用户 
			$time=date('y-m-d H:i:s',time());//$_POST['name']; //添加时间 
			$mem=$_POST['mem']; //备注 
			
			$picName1='';
			$uploadmsg=0;

		$teacher=$db->query("INSERT INTO `teacher` (
								`id` ,
								`name` ,
								`sex` ,
								`birth` ,
								`idcard` ,
								`photo` ,
								`partisan` ,
								`area` ,
								`family` ,
								`company` ,
								`phone` ,
								`tel` ,
								`email` ,
								`education` ,
								`degree` ,
								`graduation_time` ,
								`graduation_school` ,
								`work_time` ,
								`post` ,
								`title` ,
								`title_time` ,
								`office` ,
								`current` ,
								`teached` ,
								`train` ,
								`award` ,
								`user` ,
								`time` ,
								`mem` 
								)
								VALUES (
								NULL , '$name', '$sex', '$birth',  '$idcard','$photo', '$partisan', $area , '$family','$company', '$phone', '$tel', '$email', '$education', '$degree', '$graduation_time', '$graduation_school', '$work_time' , '$post', '$title','$title_time', '$office','$current','$teached', '$train', '$award', '$user' , '$time' , '$mem') ");
			
			if($teacher>=1)
			{
				 echo "<script>alert('新增成功');window.location='teacher_list.php?action=add'</script>";
			}else
			{
				 echo "<script>alert('新增失败');history.back();</script>";
			}
}
else
{
			
		echo "<script>alert('失败');history.back();</script>";
}
 ?>
